package com.msxt.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.msxt.dto.StoreupEntity;
import com.msxt.mapper.StoreupDao;
import com.msxt.result.Query;
import com.msxt.service.StoreupService;
import com.msxt.utils.PageUtils;
import com.msxt.view.StoreupView;
import com.msxt.vo.StoreupVO;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 收藏服务实现类
 */
@Service("storeupService")
public class StoreupServiceImpl extends ServiceImpl<StoreupDao, StoreupEntity> implements StoreupService {

	@Override
	public PageUtils queryPage(Map<String, Object> params) {
		Page<StoreupEntity> page = this.page(
				new Query<StoreupEntity>(params).getPage(),
				new QueryWrapper<>()
		);
		return new PageUtils(page);
	}

	@Override
	public PageUtils queryPage(Map<String, Object> params, QueryWrapper<StoreupEntity> wrapper) {
		// 防止空WHERE子句
		if (wrapper.isEmptyOfWhere()) {
			wrapper.eq("1", "1");
		}

		Page<StoreupView> page = new Query<StoreupView>(params).getPage();
		// 使用新的方法名
		page.setRecords(baseMapper.listViewPage(page, wrapper));
		return new PageUtils(page);
	}


	@Override
	public List<StoreupVO> listVO(QueryWrapper<StoreupEntity> wrapper) {
		return baseMapper.listVO(wrapper);
	}

	@Override
	public StoreupVO selectVO(QueryWrapper<StoreupEntity> wrapper) {
		return baseMapper.selectVO(wrapper);
	}

	@Override
	public List<StoreupView> listView(QueryWrapper<StoreupEntity> wrapper) {
		return baseMapper.listView(wrapper);
	}

	@Override
	public StoreupView selectView(QueryWrapper<StoreupEntity> wrapper) {
		// 防止空WHERE子句
		if (wrapper.isEmptyOfWhere()) {
			wrapper.eq("1", "1");
		}
		return baseMapper.selectView(wrapper);
	}
}